<section class="content-header">
    <h1>
        ${modelName}管理
        <small>列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="${r'${basePath}'}"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">${parFuncName?default('菜单目录')}</a></li>
        <li class="active">${modelName}管理</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="nav-tabs-custom">
                <ul class="nav nav-tabs pull-right">
                    <li><a href="#tab-content-edit" data-toggle="tab" id="nav-tab-edit"><i class="fa fa-edit"></i></a></li>
                    <li class="active"><a href="#tab-content-list" data-toggle="tab" id="nav-tab-list"><i class="fa fa-list-ul"></i></a></li>
                    <li class="pull-left header"><i class="fa fa-user"></i><small>${modelName}列表</small></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="tab-content-list">
                        <div class="box">
                            <!-- /.box-header -->
                            <div class="dataTables_filter" id="searchDiv" style="display: none">
                                <!--查询条件-->
                                <#list fields as field>
                                <#if field.isCondition="1">
                                <#if field.tagType="hidden">
                                <input type="${field.tagType}" name="${field.columnName}" id="${field.columnName}">
                                <#elseif field.tagType="text">
                                <input type="search" placeholder="请输入${field.labelName}" title="${field.labelName}" name="${field.columnName}"
                                       class="form-control" id="${field.columnName}" operator="like" likeOption="true">
                                <#elseif field.tagType="datepicker">
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="search" placeholder="开始${field.labelName}" title="${field.labelName}" name="${field.columnName}" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
                                </div>
                                ~
                                <div class="input-group">
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    <input type="search" placeholder="结束${field.labelName}" title="${field.labelName}" name="${field.columnName}" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
                                </div>
                                <#elseif field.tagType="dictSelector">
                                <select name="${field.columnName}" id="${field.columnName}" title="${field.labelName}" data-flag="dictSelector" data-code="${field.dictCode}" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width: 120px;" data-blank="true"></select>
                                <#elseif field.tagType="urlSelector">
                                <select name="${field.columnName}" id="${field.columnName}"  title="${field.labelName}"data-flag="urlSelector" data-src="${field.dictCode}" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:120px;" data-blank="true"></select>
                                <#elseif field.tagType="normalSelector">
                                <select name="${field.columnName}" id="${field.columnName}"  title="${field.labelName}" class="form-control">
                                    <option></option>
                                    <option value="0">启用</option>
                                    <option value="1">禁用</option>
                                </select>
                                <!--TODO更多类型可在此扩展-->
                                <#elseif field.tagType="radio">
                                <#if !field.dictCode??>
                                <label class="control-label"> <input type="radio" name="${field.columnName}"  value="1"> 是</label> &nbsp;
                                <label class="control-label"> <input type="radio" name="${field.columnName}"  value="0"> 否</label>
                                <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                                <input type="radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                                <#else>
                                <input type="radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                            </#if>
                            <#elseif field.tagType="icheck-radio">
                            <#if !field.dictCode??>
                            <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-green" value="1"> 是</label> &nbsp;
                            <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-green" value="0"> 否</label>
                            <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                            <input type="icheck-radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                            <#else>
                            <input type="icheck-radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                        </#if>
                        <#elseif field.tagType="checkbox">
                        <#if !field.dictCode??>
                        <label class="control-label"> <input type="checkbox" name="${field.columnName}"lang=""  value="1"> 是</label> &nbsp;
                        <label class="control-label"> <input type="checkbox" name="${field.columnName}"  value="0"> 否</label>
                        <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                        <input type="checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                        <#else>
                        <input type="checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                    </#if>
                    <#elseif field.tagType="icheck-checkbox">
                    <#if !(field.dictCode)??>
                    <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-green" value="1"> 是</label> &nbsp;
                    <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-green" value="0"> 否</label>
                    <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                    <input type="icheck-checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                    <#else>
                    <input type="icheck-checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                </#if>
            </#if>
        </#if>
    </#list>
                    <div class="btn-group">
                        <button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
                        <button type="button" class="btn btn-default" data-btn-type="reset">重置</button>
                    </div>
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" data-btn-type="add">新增</button>
                        <button type="button" class="btn btn-default" data-btn-type="edit">编辑</button>
                        <button type="button" class="btn btn-default" data-btn-type="delete">删除</button>
                    </div>
                </div>
                    <div class="box-body">
                        <table id="${htmlPrefix}_table" class="table table-bordered table-striped table-hover">
                        </table>
                    </div>
                </div>

                </div>
                    <div class="tab-pane" id="tab-content-edit">
                        <div class="box">


                            <form id="${htmlPrefix}_form" name="${htmlPrefix}_form" class="form-horizontal">
                                <input type="hidden" name="id">
                                <input type="hidden" name="version">
                                <input type="hidden" name="createDateTime" data-flag="date" data-format="yyyy-mm-dd hh:ii:ss">
                                <input type="hidden" name="deleted" value="0">
                                <input type='hidden' value="${r'${CSRFToken}'}" id='csrftoken'>
                                <div class="box-body">
                                    <#list 0..colsNum-1 as index>
                                    <div class="col-md-${12/colsNum}">
                                        <#list fields as field>
                                        <#if field_index%colsNum=index>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">${field.labelName}<#if field.validateType??&&field.validateType?contains("notEmpty")><span style="color:red">*</span></#if></label>
                                            <div class="<#if field.tagType="datepicker">input-group </#if>col-sm-8">
                                        <#if field.tagType="hidden">
                                        <input type="hidden" id="${field.columnName}" name="${field.columnName}" >
                                        <#elseif field.tagType="textarea">
                                        <textarea name="${field.columnName}" id="${field.columnName}" placeholder="请填写${field.labelName}" class="form-control"></textarea>
                                        <#elseif field.tagType="datepicker">
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                        <input type="text" placeholder="请填写${field.labelName}" name="${field.columnName}" id="${field.columnName}" data-flag="datepicker" class="form-control" data-format="yyyy-mm-dd">
                                        <#elseif field.tagType="dictSelector">
                                        <select name="${field.columnName}" id="${field.columnName}" data-code="${field.dictCode}"  data-flag="dictSelector" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:100%" data-blank="true"></select>
                                        <#elseif field.tagType="urlSelector">
                                        <select name="${field.columnName}" id="${field.columnName}" data-src="${field.dictCode}" data-flag="urlSelector" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:100%" data-blank="true"></select>
                                        <#elseif field.tagType="normalSelector">
                                        <select name="${field.columnName}" id="${field.columnName}" data-placeholder="请选择${field.labelName}" class="form-control select2" style="width:100%" data-blank="true">
                                            <option></option>
                                            <option value="0">否</option>
                                            <option value="1">是</option>
                                        </select>
                                        <#elseif field.tagType="radio">
                                        <#if !field.dictCode??>
                                        <label class="control-label"> <input type="radio" name="${field.columnName}"  value="1"> 是</label> &nbsp;
                                        <label class="control-label"> <input type="radio" name="${field.columnName}"  value="0"> 否</label>
                                        <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                                        <input type="radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                                        <#else>
                                        <input type="radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                                    </#if>
                                    <#elseif field.tagType="icheck-radio">
                                    <#if !field.dictCode??>
                                    <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-blue" value="1"> 是</label> &nbsp;
                                    <label class="control-label"> <input type="radio" name="${field.columnName}" data-flag="icheck" class="square-blue" value="0"> 否</label>
                                    <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                                    <input type="icheck-radio" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                                    <#else>
                                    <input type="icheck-radio" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                                </#if>
                                <#elseif field.tagType="checkbox">
                                <#if !field.dictCode??>
                                <label class="control-label"> <input type="checkbox" name="${field.columnName}" value="1"> 是</label> &nbsp;
                                <label class="control-label"> <input type="checkbox" name="${field.columnName}"  value="0"> 否</label>
                                <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                                <input type="checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                                <#else>
                                <input type="checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                            </#if>
                            <#elseif field.tagType="icheck-checkbox">
                            <#if !field.dictCode??>
                            <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-blue" value="1"> 是</label> &nbsp;
                            <label class="control-label"> <input type="checkbox" name="${field.columnName}" data-flag="icheck" class="square-blue" value="0"> 否</label>
                            <#elseif field.dictCode?starts_with("${r'${basePath}'}")>
                            <input type="icheck-checkbox" name="${field.columnName}" data-flag="urlSelector" data-src="${field.dictCode}">
                            <#else>
                            <input type="icheck-checkbox" name="${field.columnName}" data-flag="dictSelector" data-code="${field.dictCode}">
                        </#if>
                        <#else>
                        <input type="text" class="form-control" id="${field.columnName}" name="${field.columnName}" placeholder="请填写${field.labelName}">
                    </#if>
    </div>
    </div>
</#if>
</#list>
</div>
</#list>
</div>
<div class="box-footer text-right">
    <button type="button" class="btn btn-default" data-btn-type="cancel" data-dismiss="modal">取消</button>
    <button type="submit" class="btn btn-primary" data-btn-type="save">提交</button>
</div>
</form>
                        </div>


                    </div>

                </div>
            </div>

</div>
</div>
</section>

<script type="text/javascript">
    <#list fields as field >
    <#if field.isCondition="1">
        <#if field.tagType = "datepicker" || field.tagType = "dictSelector" || field.tagType = "urlSelector"||field.dictCode?? >
    var form = $("#searchDiv").form({baseEntity: false});
    form.initComponent();
    <#break>
    </#if>
    </#if>
    </#list >
    var ${htmlPrefix}Table, winId = "${htmlPrefix}Win";
    $(function (){
        ${htmlPrefix}Table = new CommonTable("${htmlPrefix}_table", "${queryId}", "searchDiv", null);
        //绑定按钮事件
        $("button[data-btn-type]").click(function () {
            var action = $(this).data("btn-type");
            var rowId = ${htmlPrefix}Table.getSelectedRowId();
            switch (action) {
                case "add":
                    modals.openWin({
                        winId: winId,
                        title: '新增${modelName}',
                        width: "900px",
                        url: basePath + "/${htmlPrefix}/edit"
                    })
                    break;
                case "edit":
                    if (!rowId) {
                        modals.info('请选择要编辑的行');
                        return false;
                    }
                    modals.openWin({
                        winId: winId,
                        title: '编辑${modelName}【' + ${htmlPrefix}Table.getSelectedRowData().name + '】',
                        width: '900px',
                        url: basePath + "/${htmlPrefix}/edit?id=" + rowId
                    });
                    break;
                case 'delete':
                    if (!rowId) {
                        modals.info('请选择要删除的行');
                        return false;
                    }
                    modals.confirm("是否要删除该行数据？", function () {
                        ajaxPost(basePath + "/${htmlPrefix}/delete/" + rowId, null, function (data) {
                            if (data.success) {
                                ${htmlPrefix}Table.reloadRowData();
                            } else {
                                modals.info("${modelName}数据被引用，不可删除！");
                            }
                        });
                    })
                    break;
            }
        })
    })
</script>
<script>
    var form;
    var id="${r'${id?default(0)}'}";
    $(function(){
            //初始化表单
            form=$("#${htmlPrefix}_form").form();
            //数据校验
            $("#${htmlPrefix}_form").bootstrapValidator({
                message : '请输入有效值',
                feedbackIcons : {
                    valid : 'glyphicon glyphicon-ok',
                    invalid : 'glyphicon glyphicon-remove',
                    validating : 'glyphicon glyphicon-refresh'
                },
                submitHandler : function() {
                    modals.confirm('确认保存？', function() {
                        var ${htmlPrefix} = form.getFormSimpleData();
                    <#assign isObj=1>
                            <#list fields as field>
                        <#if field.columnName?contains(".")>
                            <#assign isObj=0>
                            </#if>
                            </#list>
                        ajaxPost(basePath+'/${htmlPrefix}/save',<#if isObj=1>${htmlPrefix}<#else>{"obj":JSON.stringify(${htmlPrefix})}</#if>, function(data) {
                        if(data.success){
                            if(id!="0"){
                                modals.hideWin(winId);
                                ${htmlPrefix}Table.reloadRowData(id);
                            }else{
                                modals.hideWin(winId);
                                ${htmlPrefix}Table.reloadData();
                            }
                        }
                    });
                });
        },
        fields : {
    <#list fields as field>
        <#if field.validateType??&&field.validateType!="">
        "${field.columnName}":{
            validators:{
                ${field.validateType}
            }
        }<#if field_index+1<fields?size>,</#if>
        </#if>
        </#list>
    }
    });
    //初始化控件
    form.initComponent();
    //编辑回填
    if(id!=0){
        ajaxPost(basePath+"/${htmlPrefix}/get/"+id,null,function(data){
            form.initFormData(data);
        })
    }
    });

</script>

